//
//  RCServerListDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-27.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCServerListDataModel.h"
#import "KFObjectExtension.h"

@implementation RCServerOrderItem

@synthesize orderid = _orderid;
@synthesize name    = _name;
@synthesize reversetime = _reversetime;
@synthesize personCount =_personCount;
@synthesize type    = _type;
@synthesize phone   = _phone;
@synthesize datetime= _datetime;


- (void) dealloc
{
    KF_RELEASE_SAFELY(_orderid);
    KF_RELEASE_SAFELY(_name);
    KF_RELEASE_SAFELY(_reversetime);
    KF_RELEASE_SAFELY(_type);
    KF_RELEASE_SAFELY(_phone);
    KF_RELEASE_SAFELY(_personCount);
    KF_RELEASE_SAFELY(_datetime);
    [super dealloc];
}
@end

@implementation RCServerOrderManageListDataModel

// 将JSON数据解析为数据模型
+(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    RCServerOrderManageListDataModel *retObject = [[[RCServerOrderManageListDataModel alloc] init] autorelease];
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dataDic intValueForKey:@"total" defaultValue:0];
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dataItems) {
        dataItems = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    }
    for (NSDictionary *dic in dataItems) {
        RCServerOrderItem *item = [[RCServerOrderItem alloc] init];
        item.orderid = [dic stringValueForKey:@"orderid" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.name = [dic stringValueForKey:@"name" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.reversetime = [dic stringValueForKey:@"reversetime" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.personCount = [dic stringValueForKey:@"persons" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.type = [dic stringValueForKey:@"type" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.phone = [dic stringValueForKey:@"phone" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.datetime = [dic stringValueForKey:@"datetime" defaultValue:@"" operation:NSStringOperationTypeNone];
        [listItems addObject:item];
        [item release];
    }
    retObject.listItems = listItems;
    [listItems release];
    return retObject;
}


@end
